﻿using System;
using System.Collections.Generic;
using System.Drawing;

namespace OsuKeyboard
{
	// 缓存键盘配置数据
	class DevCfg
	{
		public static byte[,][] FlashCode = new byte[16, 16][];
		public static Color LED1_Color
		{
			get { return Color.FromArgb(FlashCode[1, 0][8], FlashCode[2, 0][8], FlashCode[3, 0][8]); }
			set { FlashCode[1, 0][8] = value.R; FlashCode[2, 0][8] = value.G; FlashCode[3, 0][8] = value.B; }
		}
		public static Color LED2_Color
		{
			get { return Color.FromArgb(FlashCode[4, 0][8], FlashCode[5, 0][8], FlashCode[6, 0][8]); }
			set { FlashCode[4, 0][8] = value.R; FlashCode[5, 0][8] = value.G; FlashCode[6, 0][8] = value.B; }
		}
		public static Color LED3_Color
		{
			get { return Color.FromArgb(FlashCode[7, 0][8], FlashCode[8, 0][8], FlashCode[9, 0][8]); }
			set { FlashCode[7, 0][8] = value.R; FlashCode[8, 0][8] = value.G; FlashCode[9, 0][8] = value.B; }
		}
		public static byte[] Key1_Word
		{
			get { return new byte[] { FlashCode[0xA, 0][8], FlashCode[0xA, 0][10] }; }
			set { FlashCode[0xA, 0][8] = value[0]; FlashCode[0xA, 0][10] = value[1]; }
		}
		public static byte[] Key2_Word
		{
			get { return new byte[] { FlashCode[0xB, 0][8], FlashCode[0xB, 0][10] }; }
			set { FlashCode[0xB, 0][8] = value[0]; FlashCode[0xB, 0][10] = value[1]; }
		}
		public static byte[] Key3_Word
		{
			get { return new byte[] { FlashCode[0xC, 0][8], FlashCode[0xC, 0][10] }; }
			set { FlashCode[0xC, 0][8] = value[0]; FlashCode[0xC, 0][10] = value[1]; }
		}
		public static byte[] Key4_Word
		{
			get { return new byte[] { FlashCode[0xD, 0][8], FlashCode[0xD, 0][10] }; }
			set { FlashCode[0xD, 0][8] = value[0]; FlashCode[0xD, 0][10] = value[1]; }
		}
		public static byte[] Key5_Word
		{
			get { return new byte[] { FlashCode[0xE, 0][8], FlashCode[0xE, 0][10] }; }
			set { FlashCode[0xE, 0][8] = value[0]; FlashCode[0xE, 0][10] = value[1]; }
		}
		public static byte LED1_Mod
		{
			get { return FlashCode[0xF, 0][8]; }
			set { FlashCode[0xF, 0][8] = value; }
		}
		public static byte LED2_Mod
		{
			get { return FlashCode[0xF, 0][10]; }
			set { FlashCode[0xF, 0][10] = value; }
		}
		public static byte LED3_Mod
		{
			get { return FlashCode[0xF, 0][12]; }
			set { FlashCode[0xF, 0][12] = value; }
		}
		public static byte LED1_TableLength
		{
			get { return FlashCode[0xF, 0][14]; }
			set { FlashCode[0xF, 0][14] = value; }
		}
		public static byte LED2_TableLength
		{
			get { return FlashCode[0xF, 0][16]; }
			set { FlashCode[0xF, 0][16] = value; }
		}
		public static byte LED3_TableLength
		{
			get { return FlashCode[0xF, 0][18]; }
			set { FlashCode[0xF, 0][18] = value; }
		}
		public static byte KeyTick
		{
			get { return FlashCode[0xF, 1][8]; }
			set { FlashCode[0xF, 1][8] = value; }
		}
		public static byte LedTick
		{
			get { return FlashCode[0xF, 1][10]; }
			set { FlashCode[0xF, 1][10] = value; }
		}
		public static Color[] LED1_ColorTable
		{
			get
			{
				Color[] getColor = new Color[LED1_TableLength];
				for (uint i = 0; i < LED1_TableLength; i++)
				{
					getColor[i] = Color.FromArgb(
						FlashCode[1, i / 16][i % 16 * 2 + 8],
						FlashCode[2, i / 16][i % 16 * 2 + 8],
						FlashCode[3, i / 16][i % 16 * 2 + 8]);
				}
				return getColor;
			}
			set
			{
				LED1_TableLength = (byte)value.Length;
				for (uint i = 0; i < value.Length; i++)
				{
					FlashCode[1, i / 16][i % 16 * 2 + 8] = value[i].R;
					FlashCode[2, i / 16][i % 16 * 2 + 8] = value[i].G;
					FlashCode[3, i / 16][i % 16 * 2 + 8] = value[i].B;
				}
			}
		}
		public static Color[] LED2_ColorTable
		{
			get
			{
				Color[] getColor = new Color[LED2_TableLength];
				for (uint i = 0; i < LED2_TableLength; i++)
				{
					getColor[i] = Color.FromArgb(
						FlashCode[4, i / 16][i % 16 * 2 + 8],
						FlashCode[5, i / 16][i % 16 * 2 + 8],
						FlashCode[6, i / 16][i % 16 * 2 + 8]);
				}
				return getColor;
			}
			set
			{
				LED2_TableLength = (byte)value.Length;
				for (uint i = 0; i < value.Length; i++)
				{
					FlashCode[4, i / 16][i % 16 * 2 + 8] = value[i].R;
					FlashCode[5, i / 16][i % 16 * 2 + 8] = value[i].G;
					FlashCode[6, i / 16][i % 16 * 2 + 8] = value[i].B;
				}
			}
		}
		public static Color[] LED3_ColorTable
		{
			get
			{
				Color[] getColor = new Color[LED3_TableLength];
				for (uint i = 0; i < LED3_TableLength; i++)
				{
					getColor[i] = Color.FromArgb(
						FlashCode[7, i / 16][i % 16 * 2 + 8],
						FlashCode[8, i / 16][i % 16 * 2 + 8],
						FlashCode[9, i / 16][i % 16 * 2 + 8]);
				}
				return getColor;
			}
			set
			{
				LED3_TableLength = (byte)value.Length;
				for (uint i = 0; i < value.Length; i++)
				{
					FlashCode[7, i / 16][i % 16 * 2 + 8] = value[i].R;
					FlashCode[8, i / 16][i % 16 * 2 + 8] = value[i].G;
					FlashCode[9, i / 16][i % 16 * 2 + 8] = value[i].B;
				}
			}
		}
	}

	// 默认灯光颜色表数据
    class DefCfg
    {
		public readonly static List<byte[]> colorAddr = new List<byte[]>
		{
			new byte[] { 0x81, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00},
			new byte[] { 0x81, 0x00, 0x00, 0x00, 0x00, 0x12, 0x00},
			new byte[] { 0x81, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00},
			new byte[] { 0x81, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00},
			new byte[] { 0x81, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00},
			new byte[] { 0x81, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00},
			new byte[] { 0x81, 0x00, 0x00, 0x00, 0x00, 0x17, 0x00},
			new byte[] { 0x81, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00},
			new byte[] { 0x81, 0x00, 0x00, 0x00, 0x00, 0x19, 0x00}
		};

        public readonly static List<byte[]> colorTable = new List<byte[]>
		{
            new byte[] {0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF},
            new byte[] {0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF},
            new byte[] {0x34,0xFF,0x34,0xF7,0x34,0xEF,0x34,0xE7,0x34,0xDF,0x34,0xD7,0x34,0xCF,0x34,0xC7,0x34,0xBF,0x34,0xB7,0x34,0xAF,0x34,0xA7,0x34,0x9F,0x34,0x97,0x34,0x8F,0x34,0x87},
            new byte[] {0x34,0x7F,0x34,0x77,0x34,0x6F,0x34,0x67,0x34,0x5F,0x34,0x57,0x34,0x4F,0x34,0x47,0x34,0x3F,0x34,0x37,0x34,0x2F,0x34,0x27,0x34,0x1F,0x34,0x17,0x34,0x0F,0x34,0x07},
            new byte[] {0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00},
            new byte[] {0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00},
            new byte[] {0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00},
            new byte[] {0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00,0x34,0x00},
            new byte[] {0x34,0x00,0x34,0x08,0x34,0x10,0x34,0x18,0x34,0x20,0x34,0x28,0x34,0x30,0x34,0x38,0x34,0x40,0x34,0x48,0x34,0x50,0x34,0x58,0x34,0x60,0x34,0x68,0x34,0x70,0x34,0x78},
            new byte[] {0x34,0x80,0x34,0x88,0x34,0x90,0x34,0x98,0x34,0xA0,0x34,0xA8,0x34,0xB0,0x34,0xB8,0x34,0xC0,0x34,0xC8,0x34,0xD0,0x34,0xD8,0x34,0xE0,0x34,0xE8,0x34,0xF0,0x34,0xF8},
            new byte[] {0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF},
            new byte[] {0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF,0x34,0xFF}
        };
    }
}